from django.db import models
from RBAC.models import Staff


# Create your models here.
# 工资表
class Salary(models.Model):
    staff = models.ForeignKey(Staff, on_delete=models.CASCADE, verbose_name='员工')
    attendance_days = models.SmallIntegerField(verbose_name='出勤天数', default=0)
    absent_days = models.SmallIntegerField(verbose_name='旷工天数', default=0)
    leave_days = models.SmallIntegerField(verbose_name='请假天数', default=0)
    base_salary = models.DecimalField(max_digits=13, decimal_places=2, verbose_name='基本工资')
    job_salary = models.DecimalField(max_digits=13, decimal_places=2, verbose_name='岗位工资')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'salary'
        verbose_name_plural = '工资表'

    def __str__(self):
        return self.staff.name


class LoginLog(models.Model):
    staff = models.ForeignKey(Staff, on_delete=models.CASCADE, verbose_name='员工')
    login_ip = models.CharField(max_length=16, verbose_name='ip地址')
    equipment = models.CharField(max_length=100, verbose_name='登录设备')
    # address = models.CharField(max_length=100, verbose_name='登录地址')
    login_time = models.DateTimeField(auto_now_add=True, verbose_name='登录时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'login_log'
        verbose_name_plural = '登录日志表'

    def __str__(self):
        return self.login_ip


# 操作日志表
class OperationLog(models.Model):
    staff = models.ForeignKey(Staff, on_delete=models.CASCADE, verbose_name='员工')
    content = models.CharField(max_length=100, verbose_name='操作内容')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'operation_log'
        verbose_name_plural = '操作日志表'

    def __str__(self):
        return self.content


# 文件材料表
class Files(models.Model):
    staff = models.ForeignKey(Staff, on_delete=models.CASCADE, verbose_name='员工')
    file_title = models.CharField(max_length=50, verbose_name='文件标题')
    file_url = models.CharField(max_length=300, verbose_name='路由地址')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'files'
        verbose_name_plural = '操作日志表'

    def __str__(self):
        return self.file_title


# 车辆信息表
class Car(models.Model):
    type = models.CharField(max_length=32, verbose_name='车辆类型')
    car_id = models.CharField(max_length=6, verbose_name='车牌号')
    status = models.BooleanField(default=False, verbose_name='车辆状态')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'car'
        verbose_name_plural = '车辆信息表'

    def __str__(self):
        return self.type


# 邮件表
class Mial(models.Model):
    send_email = models.EmailField(max_length=32, verbose_name='发件人邮箱')
    receive_email = models.EmailField(max_length=32, verbose_name='收件人邮箱')
    title = models.CharField(max_length=32, verbose_name='邮件标题')
    content = models.TextField(verbose_name='邮件内容')
    accessory = models.CharField(max_length=300, verbose_name='附件地址')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'mail'
        verbose_name_plural = '邮件表'

    def __str__(self):
        return self.title


# 抄送人表
class Copy(models.Model):
    staff = models.ForeignKey(Staff, on_delete=models.CASCADE, verbose_name='员工')
    mail = models.ForeignKey(Mial, on_delete=models.CASCADE, verbose_name='邮件id')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'copy'
        verbose_name_plural = '抄送人表'

    def __str__(self):
        return self.mail.title
